<template>
  <div id="BarChart" class="echarts" style="width: 100%; height: 350px"></div>
</template>

<script setup lang="ts">
import { ECharts, EChartsOption, init } from "echarts";
const initChart = (data: any = {}): ECharts => {
  const charEle = document.getElementById("BarChart") as HTMLElement;
  const charEch: ECharts = init(charEle);
  const option: EChartsOption = {
    tooltip: {
      trigger: "axis",
      axisPointer: {
        type: "shadow",
      },
    },
    grid: {
      left: "3%",
      right: "4%",
      bottom: "3%",
      containLabel: true,
    },
    xAxis: [
      {
        type: "category",
        data: data.yData,
        axisTick: {
          alignWithLabel: true,
        },
      },
    ],
    yAxis: [
      {
        type: "value",
      },
    ],
    series: [
      {
        name: "学院开班数据",
        type: "bar",
        barWidth: 30,
        data: data.xData,
      },
    ],
  };
  charEch.setOption(option);
  return charEch;
};
defineExpose({
  initChart,
});
</script>
<style lang="scss" scoped>
.echarts {
  width: 100%;
  height: 100%;
  margin: 0 auto;
}
</style>
